//模块主窗口
var HIGH =  HIGH||{};
HighFeeUserDataPanel = Ext.extend(Ext.Panel,{
	 closable: true,
   	 autoScroll:true,
   	 width:'100%',
   	 height:700,
   	initComponent : function() {
   		var thisPanel = this;
   		this. tbar = this.bulidBbr();
   		var dataStore = new Ext.data.JsonStore({
					url:"highFee_getTrendsChartReport.action?myFee.monitorType="+thisPanel.monitorType, 
					root: 'root',
			        idProperty: 'id',
			        fields: [
			           'statDay','yj','yif','gj','gjf','tj','tjf','userCount','feeCount'
			        ]
				});
		var now = new Date();
		var std = Ext.util.Format.date(now,'Ymd') ;
		now.setTime(now.getTime()-1000*60*60*24*31)
		var etd = Ext.util.Format.date(now,'Ymd');
		dataStore.baseParams = {
			'myFee.statDay':etd,
			'myFee.endDay':std
		}
   		var gdp = new highFeeUserDataListPanel({'monitorTypes':this.monitorType});
   		var chart = new HIGH.UserNumberChar({'monitorTypes':this.monitorType,'dataStore':dataStore});
   		var feeChart = new HIGH.UserFeeChar({'monitorTypes':this.monitorType,'dataStore':dataStore});
   		this.items = [new QueryStatHighFeeUserForm({
					thisGrid:gdp,
					chartPanel:chart
				}),feeChart,chart,gdp] ;
   		HighFeeUserDataPanel.superclass.initComponent.call(this);
   	},
    statHighFeeUser : function(btn) {
   		var cycleId = btn.ownerCt.ownerCt.cycleId.getValue();
   		var gp = btn.ownerCt.ownerCt.items.get(1) ;

   	}
   	,listeners : {
   		
   	},
   	statHighFeeUserAll : function(btn) {
   	},
   	statHighFeeUserMonth : function(btn) {
   	},
   	statHighFeeUserByCond : function(btn) {
   		 var tform = btn.ownerCt.ownerCt.formPanel;
   	     tform.show();
   	},
   	exportData:function(btn) {
   		var gp = btn.ownerCt.ownerCt.items.get(3) ;
   		var baseParams = gp.getStore().baseParams;
   		var ul = Ext.urlEncode(baseParams);
   		var monitorType =  btn.ownerCt.ownerCt.monitorType;
   		var st = gp.getStore();
   		Ext.MessageBox.confirm("确认", "确定导出?", function(btn) {
		if (btn == "yes") {
			window.location.href ="highFee_exportUserAnalysisToExcel.action?myFee.monitorType="+monitorType+"&limit="+st.totalLength+"&"+ul;
		}
		});
   		
   	} ,
   	bulidBbr: function() {
   		return [{
   				text : "显示查询",
   				iconCls: 'ico-dot-search-open',
   				handler:function(btn){
   					var m = btn.ownerCt.ownerCt;
   					var g = m.items.get(2);
   					var c = m.items.get(1);
   					var a = m.items.get(0);
   					a.setHeight(70);
   					a.searchBtn = btn;
   					if(a.collapsed) {
   						var h1 = m.getHeight()-c.getHeight()-m.tbar.dom.clientHeight-a.getHeight();
   						a.expand(true);
   						g.setHeight(h1-70);
   						btn.setText("隐藏查询");
   						btn.setIconClass("ico-dot-search-hidden");
   					} else {
   						a.collapse(true);
   						g.setHeight(m.getHeight()-m.tbar.dom.clientHeight-1);
   						btn.setText("显示查询");
   						btn.setIconClass("ico-dot-search-open");
   					}
   				}
   			}
   			,'-',{
   				text : "数据导出",
   				handler :this.exportData,
   				iconCls: 'ico-dot-report'
   			}
   			,'-',{
   				text : "隐藏用户费用趋势图",
   				handler :this.statHighFeeUser,
   				handler:function(btn){
   					var m = btn.ownerCt.ownerCt;
   					var g = m.items.get(1);
   					if(g.collapsed) {
   						g.expand();
   						btn.setText("隐藏用户费用趋势图");
   						btn.setIconClass("ico-dot-chart-del");
   					} else {
   						g.collapse();
   						btn.setText("显示用户费用趋势图");
   						btn.setIconClass("ico-dot-chart-add");
   					}
   				},
   				iconCls: 'ico-dot-chart-del'
   			},'-',{
   				text : "显示用户数量趋势图",
   				handler :this.statHighFeeUser,
   				handler:function(btn){
   					var m = btn.ownerCt.ownerCt;
   					var g = m.items.get(2);
   					if(g.collapsed) {
   						g.expand();
   						btn.setText("隐藏用户数量趋势图");
   						btn.setIconClass("ico-dot-chart-del");
   					} else {
   						g.collapse();
   						btn.setText("显示用户数量趋势图");
   						btn.setIconClass("ico-dot-chart-add");
   					}
   				},
   				iconCls: 'ico-dot-chart-add'
   			}
//  			,'-',{
//   				text : "每日金额趋势图",
//   				handler :this.statHighFeeUser,
//   				chartType:"Y",
//   				iconCls: 'ico-dot-report6',
//   				handler:function(btn){
//   					var m = btn.ownerCt.ownerCt;
//   					var g = m.items.get(2);
//   					var c = m.items.get(1);
//   					var a = m.items.get(0);
//   					a.setHeight(70);
//   					a.searchBtn = btn;
//   					if(a.collapsed) {
//   						var h1 = m.getHeight()-c.getHeight()-m.tbar.dom.clientHeight-a.getHeight();
//   						a.expand(true);
//   						g.setHeight(h1-70);
//   					} else {
//   						a.collapse(true);
//   						g.setHeight(m.getHeight()-c.getHeight()-m.tbar.dom.clientHeight-1);
//   					}
//   				}
//   			}
//   			,'-',{
//   				text : "月度分析统计走势图",
//   				handler :this.statHighFeeUserMonth,
//   				iconCls: 'ico-dot-report5'
//   			}
   			,'->',{
                     text:'使用说明'          
                      ,iconCls:'ico-dot-book-question'
                      ,handler:function(btn){
                      var m = btn.ownerCt.ownerCt.monitorType;
                      if(m==1){
                        SM.Explanation.showExplanation(14);
                      }
                      if(m==2){
                        SM.Explanation.showExplanation(10);
                      }
                      if(m==3){
                        SM.Explanation.showExplanation(12);
                      }
                      if(m==4){
                        SM.Explanation.showExplanation(22);
                      }
                      if(m==5){
                        SM.Explanation.showExplanation(24);
                      }
                    }
                   }
   			] ;
   	}
});


//高额用户统计信息列表
highFeeUserDataListPanel = Ext.extend(Ext.grid.EditorGridPanel,{
	title : '告警信息列表',
	header: false,
	loadMask:{msg:'加载中...'},
	columnLines:true,
	enableDragDrop: false,
	headerAlign:"center",
	height: 600,
	viewConfig :{
         forceFit: true
    },
	initComponent : function() {
		var thisGrid = this;
       	this.recordStart = 1 ;
		var rn = new　Ext.grid.RowNumberer({
		　　header　:　"序号",
		　　width　:　35,
		　　renderer:function(value,metadata,record,rowIndex){
		　　　return　　thisGrid.recordStart　+　rowIndex;
		　　}
		});
		
		this.columns　 = this.buildColUI(rn);
		var dataStore = new Ext.data.JsonStore({
			url : 'highFee_getHighFeeAnalysisList.action?myFee.monitorType='+this.monitorTypes,
			root: 'root',
	        totalProperty: 'totalProperty',
	        idProperty: 'id',
	        fields: [
	           'eparchyCode','bizType','netTypeCode','curstatus','curfee','temCount','cycleid','eparchyName'
	        ]
			});
		    dataStore.baseParams ={'highFeeUserData':null};
			this.store = dataStore;
			//this.sm=highFeeUserData;
			this.bbar = new Ext.PagingToolbar({
			pageSize : 100,
			store : dataStore,
			displayInfo : true,
			displayMsg : '第 {0} - {1} 条  共 {2} 条',
			emptyMsg : "没有记录",
			listeners:{
				beforechange:function(pt,obj) {
					thisGrid.recordStart = obj.start+1 ;
				    
				}
			}
		});
		
		highFeeUserDataListPanel.superclass.initComponent.call(this);
	},listeners : {
   		'afterrender':function(com) {
//   			com.getStore().load({
//					params:{
//					start:0,
//					limit:100
//					}
//			});
   		}
   	},
	buildColUI:function(rn) {
		return [rn,{
				header:'账期',
				sortable:true,
				dataIndex:"cycleid",
				width:60,
				align:"center"
			},　
		   {
				header:'归属地市',
				sortable:true,
				dataIndex:"eparchyName",
				align:"center"
			},{
				header:'客户类型',
				sortable:true,
				dataIndex:"netTypeCode",
				width:100,
				renderer:changerNetTypeCode,
				align:"center"
			},{
			    header:'业务类型',
				sortable:true,
				dataIndex:"bizType",
				width:100,
				renderer:changerBizTypeNew,
				align:"center"
			},{
				header:'费用金额(元)',
				sortable:true,
				dataIndex:"curfee",
				width:100,
				headerAlign:"center",
				align:"right",
				renderer:Ext.util.Format.chMoney
			},{
				header:'用户数量',
				sortable:true,
				dataIndex:"temCount",
				width:100,
				align:"center"
			},{
				header:'告警级别',
				sortable:true,
				dataIndex:"curstatus",
				width:62,
				renderer:changerStatus,
				align:"center"
			}
		] ;
	}
});


//按条件统计高额用户
QueryStatHighFeeUserForm = Ext.extend(Ext.form.FormPanel,{
	text:"表单",
	layout:"form",
	region : "center",
	labelAlign:"right",
	collapsible:true,
	collapsed:false,
	header:false,
	width:"100%",
	height:1,
	frame:true,
	layout:'table',
	layoutConfig:{
	tableAttrs: {
		align:'left'
	 },
	columns: 5
 	},
	initComponent: function(){
	this.items=[{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '归属地市',
							name : 'eparchy_code',
							xtype : 'combo',
							editable : false,
							mode : 'remote',
							triggerAction : 'all',
							valueField: "paramValue",
   							displayField: "displayValue",
							store : areaCodeSelect,
							emptyText:"请选择",
							anchor:"90%",
							width:100
						}]},{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '开始日期',
							name : 'statDay',
							xtype:"datefield",
							editable : false,
							format:'Y-m-d',
							emptyText:"请选择",
							width:100
					    }]},{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '结束日期',
							name : 'endDay',
							xtype:"datefield",
							editable : false,
							format:'Y-m-d',
							emptyText:"请选择",
							width:100
					    }]},{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '客户类型',
							name : 'net_type_code',
							xtype : 'combo',
							editable : false,
							mode : 'local',
							triggerAction : 'all',
							emptyText:"请选择",
							store : [[null,'全部'],['10','2G用户'],['33','3G用户']],
							anchor:"90%",
							width:100
						 }]}
//						 ,{ 
//		    	layout : "form",
//		    	xtype:'panel',
//		    	colspan:1,
//		    	items:[{fieldLabel : '业务类型',
//							name : 'biz_type',
//							xtype : 'combo',
//							editable : false,
//							mode : 'local',
//							triggerAction : 'all',
//							emptyText:"请选择",
//							store : [[null,'全部'],['1','语音'],['2','短信'],['3','GPRS']],
//							anchor:"90%",
//							width:100
//						}]}
						 ,{ 
		    	layout : "form",
		    	xtype:'panel',
		    	colspan:1,
		    	items:[{fieldLabel : '告警级别',
							name : 'curstatus',
							xtype : 'combo',
							editable : false,
							mode : 'local',
							triggerAction : 'all',
							emptyText:"请选择",
							store : [[null,'全部'],['1','预警'],['2','警告'],['3','严重'],['4','紧急']],
							anchor:"90%",
							width:100
						}]}
		];
	  QueryStatHighFeeUserForm.superclass.initComponent.call(this);
	},
	buttonAlign :'center',
	minButtonWidth:60,
	buttons:[{
		text:"确定",
		handler : function(btn){
		    var thisForm = btn.ownerCt.ownerCt.getForm();
		    var eparchy_code  = thisForm.findField('eparchy_code').getValue();
		    var net_type_code = thisForm.findField('net_type_code').getValue();
		    //var biz_type = thisForm.findField('biz_type').getValue();
		    var curstatus = thisForm.findField('curstatus').getValue();
            var statDay = thisForm.findField('statDay').getValue();	 
		    	statDay = statDay?statDay.format("Ymd"):"";	
		    var endDay = thisForm.findField('endDay').getValue();	 
		    	endDay = endDay?endDay.format("Ymd"):"";	
		    var store1 = btn.ownerCt.ownerCt.chartPanel.store;
		    var store2 = btn.ownerCt.ownerCt.thisGrid.getStore();
		    btn.ownerCt.ownerCt.thisGrid.recordStart = 1;
		    var baseParams = {
		    			'myFee.eparchyCode':eparchy_code,
		    			'myFee.statDay':statDay,
		    			'myFee.endDay':endDay,
		    			'myFee.netTypeCode':net_type_code,
		    			//'myFee.bizType':biz_type,
		    			'myFee.curstatus':curstatus
			};
			store1.baseParams = baseParams;
			store2.baseParams = baseParams;
			store1.load({
				callback:function(){
					store2.load({params:{start:0, limit:100}});
				}
			})
            
		    
		   //this.ownerCt.ownerCt.ownerCt.hide();//隐藏弹出页面
		}
	}
	, {
		text : '关闭',
		handler : function() {
		this.ownerCt.ownerCt.collapse(true);
			var m = this.ownerCt.ownerCt.ownerCt;
   					var g = m.items.get(2);
   					var c = m.itmes.get(1);
   					var a = m.items.get(0);
			g.setHeight(m.getHeight()-c.getHeught()-m.tbar.dom.clientHeight-1);
   			this.ownerCt.ownerCt.searchBtn.setText("显示查询");
   			this.ownerCt.ownerCt.searchBtn.setIconClass("ico-dot-search-open");
		}
	}]
});

HIGH.UserNumberChar = Ext.extend(Ext.Panel,{
	        width: "100%",
	        collapsible:true,
	        hideCollapseTool:true,
			collapsed:true,
			title:'每日用户量趋势图',
	        height: 350,
	        initComponent: function(){
	        	var thisPanel = this;
		        var dataStore = this.dataStore;
				//dataStore.load();
				this.store = dataStore;
		        this.items = [{
		            xtype: 'linechart',
		            store: dataStore,
		            plugins:[new Ext.ux.plugin.VisibilityMode()],
		            yAxis: new Ext.chart.NumericAxis({  
			            title: '异常用户数(户)'
			        })
			        ,tipRenderer : function(chart, record, index, series){
			        	if(series.yField=="yj") {
			        		return series.displayName+"\n"+series.data[index]['statDay']+"\n"+Ext.util.Format.number(series.data[index]['yj'])+"户";
			        	}else if(series.yField=="tj") {
			        		return series.displayName+"\n"+series.data[index]['statDay']+"\n"+Ext.util.Format.number(series.data[index]['tj'])+"户";
			        	}else if(series.yField=="gj") {
			        		return series.displayName+"\n"+series.data[index]['statDay']+"\n"+Ext.util.Format.number(series.data[index]['gj'])+"户";
			        	}else if(series.yField=="userCount") {
			        		return series.displayName+"\n"+series.data[index]['statDay']+"\n"+Ext.util.Format.number(series.data[index]['userCount'])+"户";
			        	}
			        }
			        ,extraStyle: {
			        	xAxis: {  
			                labelRotation: -30//x轴标题旋转度数
			                ,majorGridLines: {size: 1, color: 0xdfe8f6}
			                ,majorTicks: {color: 0x69aBc8, length: 4},
                   			 minorTicks: {color: 0x69aBc8, length: 2}
			            },  
			            yAxis: {  
			                labelRotation: 0//y轴标题旋转度数  
			            	,titleRotation:-90
			            	,majorGridLines: {size: 1, color: 0xeeeeee}
//			            	,majorTicks: {color: 0x69aBc8, length: 4},
//                   			 minorTicks: {color: 0x69aBc8, length: 2}
			            } ,
			            legend:{
			            	display:'top'
			            }
			            ,visibility:false
			        }  
		            ,series: [{
		                displayName: '预警用户',
		                type: 'line',
		            	yField: 'yj',
		            	xField: 'statDay',
		                style: {
		                	size:8
		                }
		            },{
		                 type: 'line',
		            	yField: 'gj',
		            	xField: 'statDay',
		                displayName: '告警用户',
		                style: {
		                	color:0xffff00,
		                	size:8
		                }
		            },{
		                 type: 'line',
		            	yField: 'tj',
		            	xField: 'statDay',
		                displayName: '严重用户',
		                style: {
		                	color:0xFF0080,
		                	size:8
		                }
		            },{
		                type: 'line',
		            	yField: 'userCount',
		            	xField: 'statDay',
		                displayName: '总用户量',
		                style: {
		                	color:0x800080,
		                	size:8
		                }
		            }
//		            ,{
//		                type: 'line',
//		            	yField: 'feeCount',
//		            	xField: 'statDay',
//		                displayName: '总费用'
//		            }
		            ]
		        }];
		        HIGH.UserNumberChar.superclass.initComponent.call(this);
	        },listeners : {
   			'afterrender':function(com) {
	   				com.store.load({callback:function(){
	   					com.ownerCt.items.get(3).getStore().load({
	   						params:{
								start:0,
								limit:100
							}
	   					})
	   				}});
   				}
   	}
	    });
HIGH.UserFeeChar = Ext.extend(Ext.Panel,{
	        width: "100%",
	        collapsible:true,
	        hideCollapseTool:true,
			collapsed:false,
			title:'每日用户费用趋势图',
	        height: 350,
	        initComponent: function(){
	        	var thisPanel = this;
		        var dataStore = this.dataStore;
				this.store = dataStore;
		        this.items = [{
		            xtype: 'linechart',
		            store: dataStore,
		            plugins:[new Ext.ux.plugin.VisibilityMode()],
		            yAxis: new Ext.chart.NumericAxis({  
			            title: '异常费用(元)'
			        })
			        ,tipRenderer : function(chart, record, index, series){
			        	if(series.yField=="yjf") {
			        		return series.displayName+"\n"+series.data[index]['statDay']+"\n"+Ext.util.Format.chMoney(series.data[index]['yjf'])+"元";
			        	}else if(series.yField=="tjf") {
			        		return series.displayName+"\n"+series.data[index]['statDay']+"\n"+Ext.util.Format.chMoney(series.data[index]['tjf'])+"元";
			        	}else if(series.yField=="gjf") {
			        		return series.displayName+"\n"+series.data[index]['statDay']+"\n"+Ext.util.Format.chMoney(series.data[index]['gjf'])+"元";
			        	}else if(series.yField=="feeCount") {
			        		return series.displayName+"\n"+series.data[index]['statDay']+"\n"+Ext.util.Format.chMoney(series.data[index]['feeCount'])+"元";
			        	}
			        }
			        ,extraStyle: {
			        	xAxis: {  
			                labelRotation: -30//x轴标题旋转度数
			                ,majorGridLines: {size: 1, color: 0xdfe8f6}
			                ,majorTicks: {color: 0x69aBc8, length: 4},
                   			 minorTicks: {color: 0x69aBc8, length: 2}
			            },  
			            yAxis: {  
			                labelRotation: 0//y轴标题旋转度数  
			            	,titleRotation:-90
			            	,majorGridLines: {size: 1, color: 0xeeeeee}
//			            	,majorTicks: {color: 0x69aBc8, length: 4},
//                   			 minorTicks: {color: 0x69aBc8, length: 2}
			            } ,
			            legend:{
			            	display:'top'
			            }
			            ,visibility:false
			        }  
		            ,series: [{
		                displayName: '预警总费用',
		                type: 'line',
		            	yField: 'yjf',
		            	xField: 'statDay',
		                style: {
		                	size:8
		                }
		            },{
		                type: 'line',
		            	yField: 'gjf',
		            	xField: 'statDay',
		                displayName: '告警总费用',
		                style: {
		                	color:0xffff00,
		                	size:8
		                }
		            },{
		                 type: 'line',
		            	yField: 'tjf',
		            	xField: 'statDay',
		                displayName: '严重总费用',
		                style: {
		                	color:0xFF0080,
		                	size:8
		                }
		            },{
		                type: 'line',
		            	yField: 'feeCount',
		            	xField: 'statDay',
		                displayName: '总费用',
		                style: {
		                	color:0x800080,
		                	size:8
		                }
		            }
		            ]
		        }];
		        HIGH.UserFeeChar.superclass.initComponent.call(this);
	        },listeners : {
   			'afterrender':function(com) {
   				}
   	}
	    });